package com.standardoperationapp.utils;

public class StringUtil {
    /**
     * 字符串转换16进制
     * @param input
     * @return
     */
    public static String stringToHex(String input) {
        StringBuilder sb = new StringBuilder();
        sb.append(input);
        while (sb.length() < 16) {
            sb.insert(0, '0');
        }
        StringBuilder output = new StringBuilder();
        for (char c : sb.toString().toCharArray()) {
            output.append(String.format("%02X", (int) c));
        }
        return output.toString();
    }

    /**
     * 16进制转换字符串
     * @param hex
     * @return
     */
    public static  String hexToString(String hex) {
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < hex.length(); i += 2) {
            String str = hex.substring(i, i + 2);
            output.append((char) Integer.parseInt(str, 16));
        }
        return output.toString();
    }
}
